#include "FourierFiltering.h"
#include "ui_FourierFiltering.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    setFixedSize (1600,680);
    setWindowTitle ("医疗设备数据采集软件");
    treeVBoxLayout =  new QVBoxLayout();
    treeVBoxLayout2=  new QVBoxLayout();
    hardwareTreeWidget = new QTreeWidget();
    algorithmTreeWidget = new QTreeWidget();
    checkBox1=new QCheckBox();
    processBar=new QProgressBar();
    processBar2=new QProgressBar();
    lineEdit1=new QLineEdit();
    lineEdit2=new QLineEdit();
    lineEdit3=new QLineEdit();
    hardwareTreeWidget->setHeaderHidden (true);
    hardwareTreeWidget->setHeaderLabel (QString("      Hardware                                  Value  "));
    algorithmTreeWidget->setHeaderHidden (false);
    algorithmTreeWidget->setHeaderLabel (QString("      Measurments                                   Value  "));
    scene = new QGraphicsScene();
    scene2= new QGraphicsScene();
    addHardwareTreeWidgetToGroupBox ();
    addAlgorithmTreeWidgetToGroupBox ();
    ui->verticalSlider->setEnabled (true);
    GetSourceImage ();
    FoulerFilttering ();
    disPlayFiltterImage ();
}

Widget::~Widget()
{
    delete ui;
    Free();
}



/**
* 添加Tree Widget
*/
void Widget::addHardwareTreeWidgetToGroupBox (){
    // 为垂直布局里添加有一个TreeWidget
    treeVBoxLayout->addWidget (hardwareTreeWidget);
    // 设置groupbox的大小
    ui->H_And_A_groupBox->setFixedWidth (320);
    // 设置Tree Widget的布局
    ui->H_And_A_groupBox->setLayout (treeVBoxLayout);

    // 初始化一个Tree Item1
    TreeWidgetItemVector.push_back (new QTreeWidgetItem(hardwareTreeWidget));
    // 为这个item设置部件组合
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));                                               //创建一个widget
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));                              // 为当前的widget设置垂直布局
    LabelVector.push_back (new QLabel("Binning"));                                                        // 创建label
    QComboBox* combox1=new QComboBox();                                                                  // 创建复选框
    QStringList items1;
    combox1->addItems(items1<<"1"<<"其他");                                                              //为复选框添加内容
    ComboxVector.push_back (combox1);                                                                  // 将复选框推入管理的vector
    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());                                // 为布局添加label
    (WidgetHBoxLayoutVector.back ())->addWidget (ComboxVector.back ());                              // 为布局添加复选框
    hardwareTreeWidget->setItemWidget (TreeWidgetItemVector.back (),0,WidgetVector.back ());        //添加一个item 这个item由后面的窗口组建



    connect (combox1,QOverload<int>::of(&QComboBox::currentIndexChanged),[&](int index) -> int {
        QMessageBox::information (hardwareTreeWidget," ","暂未开发的接口");                       // 暂未开发的接口
        return index;
    });




    // 初始化一个Tree Item2 和 Tree item1 平级
    TreeWidgetItemVector.push_back (new QTreeWidgetItem(hardwareTreeWidget));
    // 为这个item设置部件组合
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));                                            //创建一个widget
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));                           // 为当前的widget设置垂直布局
    LabelVector.push_back (new QLabel("Trigger  Source"));                                             // 创建label
    QComboBox* combox2=new QComboBox();                                                               // 创建复选框
    QStringList items2;
    combox2->addItems(items2<<"Internal"<<"其他");                                                   //为复选框添加内容
    ComboxVector.push_back (combox2);
    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());                             // 为布局添加label
    (WidgetHBoxLayoutVector.back ())->addWidget (ComboxVector.back ());                           // 为布局添加复选框
    hardwareTreeWidget->setItemWidget (TreeWidgetItemVector.back (),0,WidgetVector.back ());     //添加一个item 这个item由后面的窗口组建




    connect (combox2,QOverload<int>::of(&QComboBox::currentIndexChanged),[&](int index) -> int {
        QMessageBox::information (hardwareTreeWidget," ","暂未开发的接口");                   // 暂未开发的接口
        return index;
    });




    // 初始化一个Tree Item3 和 Tree item1，Tree item2 平级
    TreeWidgetItemVector.push_back (new QTreeWidgetItem(hardwareTreeWidget));
    // 为这个item设置部件组合
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));                                               //创建一个widget
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));                              // 为当前的widget设置垂直布局
    LabelVector.push_back (new QLabel("Trigger  Mode"));                                                  // 创建label
    QComboBox* combox3=new QComboBox();                                                                  // 创建复选框
    QStringList items3;
    combox3->addItems(items3<<"Normal"<<"其他");                                                        //为复选框添加内容
    ComboxVector.push_back (combox3);
    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());                                // 为布局添加label
    (WidgetHBoxLayoutVector.back ())->addWidget (ComboxVector.back ());                              // 为布局添加复选框
    hardwareTreeWidget->setItemWidget (TreeWidgetItemVector.back (),0,WidgetVector.back ());        //添加一个item 这个item由后面的窗口组建



    connect (combox3,QOverload<int>::of(&QComboBox::currentIndexChanged),[&](int index) -> int {
        QMessageBox::information (hardwareTreeWidget," ","暂未开发的接口");                      // 暂未开发的接口
        return index;
    });




    // 初始化一个Tree Item4 和 Tree item1,2,3 平级
    TreeWidgetItemVector.push_back (new QTreeWidgetItem(hardwareTreeWidget));
    // 为这个item设置部件组合
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));                                                 //创建一个widget
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));                                // 为当前的widget设置垂直布局
    LabelVector.push_back (new QLabel("Trigger  Polarity"));                                                // 创建label
    QComboBox* combox4=new QComboBox();                                                                    // 创建复选框
    QStringList items4;
    combox4->addItems(items4<<"P"<<"N");                                                                 //为复选框添加内容
    ComboxVector.push_back (combox4);
    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());                                 // 为布局添加label
    (WidgetHBoxLayoutVector.back ())->addWidget (ComboxVector.back ());                               // 为布局添加复选框
    hardwareTreeWidget->setItemWidget (TreeWidgetItemVector.back (),0,WidgetVector.back ());         //添加一个item 这个item由后面的窗口组建



    connect (combox4,QOverload<int>::of(&QComboBox::currentIndexChanged),[&](int index) -> int {
        QMessageBox::information (hardwareTreeWidget," ","暂未开发的接口");                        // 暂未开发的接口
        return index;
    });




    // 初始化一个Tree Item5 和 Tree item1,2,3，4 平级
    TreeWidgetItemVector.push_back (new QTreeWidgetItem(hardwareTreeWidget));
    // 为这个item设置部件组合
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));                                               //创建一个widget
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));                              // 为当前的widget设置垂直布局
    LabelVector.push_back (new QLabel("Trigger  Active"));                                                // 创建label
    QComboBox* combox5=new QComboBox();                                                                  // 创建复选框
    QStringList items5;
    combox5->addItems(items5<<"Edge"<<"其他");                                                          //为复选框添加内容
    ComboxVector.push_back (combox5);
    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());                                // 为布局添加label
    (WidgetHBoxLayoutVector.back ())->addWidget (ComboxVector.back ());                              // 为布局添加复选框
    hardwareTreeWidget->setItemWidget (TreeWidgetItemVector.back (),0,WidgetVector.back ());        //添加一个item 这个item由后面的窗口组建


    connect (combox5,QOverload<int>::of(&QComboBox::currentIndexChanged),[&](int index) -> int {
        QMessageBox::information (hardwareTreeWidget," ","暂未开发的接口");                        // 暂未开发的接口
        return index;
    });



    // 初始化一个Tree Item5 和 Tree item1,2,3，4 平级
    TreeWidgetItemVector.push_back (new QTreeWidgetItem(hardwareTreeWidget));
    // 为这个item设置部件组合
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));                             //创建一个widget
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));            // 为当前的widget设置垂直布局
    LabelVector.push_back (new QLabel("Logged  Quantities"));                           // 创建label
    QToolButton* toolButton1=new  QToolButton();                                       // 创建一个toolbutton
    toolButton1->setText (QString("Read From Hardware"));
    QFont font("Courier New");
    font.setBold (true);
    toolButton1->setFont (font);
    toolButton1->setStyleSheet (QString( "QToolButton{"
                                         "background-color: rgb(170, 170, 127);"
                                         "border-radius: 10px;"
                                         "border: 2px solid #999;"
                                     "}"));                                                           //设置样式

    ToolButtonVector.push_back (toolButton1);
    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());                             // 为布局添加label
    (WidgetHBoxLayoutVector.back ())->addWidget (ToolButtonVector.back ());                       // 为布局添加复选框
    hardwareTreeWidget->setItemWidget (TreeWidgetItemVector.back (),0,WidgetVector.back ());     //添加一个item 这个item由后面的窗口组建


    connect(toolButton1,&QToolButton::clicked,[&]() -> void {
        QMessageBox::information (hardwareTreeWidget,"Data","暂未开发的接口");                  // 暂未开发的接口

    } );


    // 添加一个新的Tree Item 装载不同的硬件  它包含了具体的一些数值参数设置..........................
    TreeWidgetItemVector.push_back (new QTreeWidgetItem(hardwareTreeWidget));
    (TreeWidgetItemVector.back ())->setText (0,"Laser488 Hardware");
    TreeWidgetItemVector.back ()->setExpanded (true);



    // 添加一个新的Tree Item 装载不同的硬件  它包含了具体的一些数值参数设置..........................
    TreeWidgetItemVector.push_back (new QTreeWidgetItem(hardwareTreeWidget));
    (TreeWidgetItemVector.back ())->setText (0,"Laser561 Hardware");
    TreeWidgetItemVector.back ()->setExpanded (true);



    // 添加一个新的Tree Item 装载不同的硬件  它包含了具体的一些数值参数设置..........................
    TreeWidgetItemVector.push_back (new QTreeWidgetItem(hardwareTreeWidget));
    (TreeWidgetItemVector.back ())->setText (0,"NanoScan Hardware");
    TreeWidgetItemVector.back ()->setExpanded (true);

    // NanoScan Hardware的第一个二级Tree Item
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Connected"));
    (WidgetHBoxLayoutVector.back())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back())->addWidget (checkBox1);
    hardwareTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back());

    // NanoScan Hardware的第二个二级Tree Item
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Com Port"));
    QComboBox* combox6= new QComboBox();
    QList<QSerialPortInfo> serialPortList=QSerialPortInfo::availablePorts();
    for (auto& port : serialPortList ) {
        combox6->addItem(port.portName ());
    }
    ComboxVector.push_back (combox6);
    (WidgetHBoxLayoutVector.back())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back())->addWidget (ComboxVector.back ());
    hardwareTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back());



    // NanoScan Hardware的第三个二级Tree Item
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Relative Postion"));

    QDoubleSpinBox* doubleSpinBox1= new QDoubleSpinBox();
    doubleSpinBox1->setValue (0);
    doubleSpinBox1->setSingleStep (0.1);
    doubleSpinBox1->setSuffix (" um");
    DoubleSpinBoxVec.push_back (doubleSpinBox1);

    (WidgetHBoxLayoutVector.back())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back())->addWidget (DoubleSpinBoxVec.back ());
    hardwareTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back());



    // NanoScan Hardware的第四个二级Tree Item
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Asolute Postion"));

    QDoubleSpinBox* doubleSpinBox2= new QDoubleSpinBox();
    doubleSpinBox2->setValue (0);
    doubleSpinBox2->setSingleStep (0.1);
    doubleSpinBox2->setSuffix (" um");
    DoubleSpinBoxVec.push_back (doubleSpinBox2);


    (WidgetHBoxLayoutVector.back())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back())->addWidget (DoubleSpinBoxVec.back ());
    hardwareTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back());



    // NanoScan Hardware的第五个二级Tree Item
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Move Distance"));


    QDoubleSpinBox* doubleSpinBox3= new QDoubleSpinBox();
    doubleSpinBox3->setValue (0);
    doubleSpinBox3->setSingleStep (0.1);
    DoubleSpinBoxVec.push_back (doubleSpinBox3);


    (WidgetHBoxLayoutVector.back())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back())->addWidget (DoubleSpinBoxVec.back ());
    hardwareTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back());



    // NanoScan Hardware的第六个二级Tree Item
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Step Size"));


    QDoubleSpinBox* doubleSpinBox4= new QDoubleSpinBox();
    doubleSpinBox4->setValue (0);
    doubleSpinBox4->setSingleStep (0.1);
    DoubleSpinBoxVec.push_back (doubleSpinBox4);


    (WidgetHBoxLayoutVector.back())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back())->addWidget (DoubleSpinBoxVec.back ());
    hardwareTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back());



    // NanoScan Hardware的第七个二级Tree Item
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(hardwareTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Travel Range"));

    QDoubleSpinBox* doubleSpinBox5= new QDoubleSpinBox();
    doubleSpinBox5->setValue (0);
    doubleSpinBox5->setSingleStep (0.1);
    doubleSpinBox5->setSuffix (" um");
    DoubleSpinBoxVec.push_back (doubleSpinBox5);



    (WidgetHBoxLayoutVector.back())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back())->addWidget (DoubleSpinBoxVec.back ());
    hardwareTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back());


}



void Widget::addAlgorithmTreeWidgetToGroupBox (){
    // 创建一个算法窗口
    treeVBoxLayout2->addWidget (algorithmTreeWidget);
    ui->AlgorithmGroupBox->setFixedWidth (320);
    ui->AlgorithmGroupBox->setLayout (treeVBoxLayout2);
    // 初始化一个顶级Tree Item
    TreeWidgetItemVector.push_back (new QTreeWidgetItem(algorithmTreeWidget));
    TreeWidgetItemVector.back ()->setExpanded (true);
    TreeWidgetItemVector.back() ->setText (0,"Hexsim Measurment");


    //创建Hexsim Measurment第一个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Activation"));

    AlgoTreeWdCheckBoxVec.push_back (new QCheckBox());

    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (AlgoTreeWdCheckBoxVec.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());





    //创建Hexsim Measurment第二个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Running"));

    AlgoTreeWdCheckBoxVec.push_back (new QCheckBox());


    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (AlgoTreeWdCheckBoxVec.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());



    //创建Hexsim Measurment第三个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Progress"));
    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());

    (WidgetHBoxLayoutVector.back ())->addWidget (processBar2);

    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());



    //创建Hexsim Measurment第四个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Profile"));

    AlgoTreeWdCheckBoxVec.push_back (new QCheckBox());

    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (AlgoTreeWdCheckBoxVec.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());



    //创建Hexsim Measurment第五个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Save .H5 Data"));

    AlgoTreeWdCheckBoxVec.push_back (new QCheckBox());

    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (AlgoTreeWdCheckBoxVec.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());





    //创建Hexsim Measurment第六个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Refresh Period"));

    QDoubleSpinBox* doubleSpinBox1= new QDoubleSpinBox();
    doubleSpinBox1->setValue (0);
    doubleSpinBox1->setSingleStep (0.01);
    doubleSpinBox1->setSuffix (" s");
    DoubleSpinBoxVec.push_back (doubleSpinBox1);


    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (DoubleSpinBoxVec.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());





    //创建Hexsim Measurment第七个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Auto Range"));

    AlgoTreeWdCheckBoxVec.push_back (new QCheckBox());
    AlgoTreeWdCheckBoxVec.back ()->setChecked (true);

    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (AlgoTreeWdCheckBoxVec.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());





    //创建Hexsim Measurment第八个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Auto Levels"));

    AlgoTreeWdCheckBoxVec.push_back (new QCheckBox());
    AlgoTreeWdCheckBoxVec.back ()->setChecked (true);

    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (AlgoTreeWdCheckBoxVec.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());





    //创建Hexsim Measurment第八个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Levels Min"));

    QSpinBox *spinBox1= new QSpinBox();
    spinBox1->setValue (0);
    spinBox1->setSingleStep (1);
    SpinBoxVector.push_back (spinBox1);

    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (SpinBoxVector.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());




    //创建Hexsim Measurment第八个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Levels  Max"));

    QSpinBox *spinBox2= new QSpinBox();
    spinBox2->setValue (0);
    spinBox2->setSingleStep (1);
    SpinBoxVector.push_back (spinBox2);


    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (SpinBoxVector.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());





    //创建Hexsim Measurment第八个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Threshold"));

    QSpinBox *spinBox3= new QSpinBox();
    spinBox3->setValue (0);
    spinBox3->setSingleStep (1);
    SpinBoxVector.push_back (spinBox3);

    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (SpinBoxVector.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());





    //创建Hexsim Measurment第八个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Start"));


    QToolButton* toolStartBtn=new QToolButton();
    toolStartBtn->setText ("Start");
    QFont font("Courier New");
    font.setBold (true);
    toolStartBtn->setFont (font);
    toolStartBtn->setStyleSheet (QString( "QToolButton{"
                                         "background-color: rgb(170, 170, 127);"
                                         "border-radius: 10px;"
                                         "border: 2px solid #999;"
                                     "}"));

    ToolButtonVector.push_back (toolStartBtn);

    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (ToolButtonVector.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());





    //创建Hexsim Measurment第八个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Interrupt"));

    QToolButton* toolInterruptBtn=new QToolButton();
    toolInterruptBtn->setText ("Interrupt");

    toolInterruptBtn->setFont (font);
    toolInterruptBtn->setStyleSheet (QString( "QToolButton{"
                                         "background-color: rgb(170, 170, 127);"
                                         "border-radius: 10px;"
                                         "border: 2px solid #999;"
                                     "}"));


    ToolButtonVector.push_back (toolInterruptBtn);

    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (ToolButtonVector.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());







    //创建Hexsim Measurment第八个二级标题
    SecondaryTreeWidgetItemVec.push_back (new QTreeWidgetItem(TreeWidgetItemVector.back ()));
    WidgetVector.push_back (new QWidget(algorithmTreeWidget));
    WidgetHBoxLayoutVector.push_back (new QHBoxLayout(WidgetVector.back ()));
    LabelVector.push_back (new QLabel("Update Display"));


    QToolButton* toolUpdateDisplayBtn=new QToolButton();
    toolUpdateDisplayBtn->setText ("Interrupt");

    toolUpdateDisplayBtn->setFont (font);
    toolUpdateDisplayBtn->setStyleSheet (QString( "QToolButton{"
                                         "background-color: rgb(170, 170, 127);"
                                         "border-radius: 10px;"
                                         "border: 2px solid #999;"
                                     "}"));


    ToolButtonVector.push_back (toolUpdateDisplayBtn);


    (WidgetHBoxLayoutVector.back ())->addWidget (LabelVector.back ());
    (WidgetHBoxLayoutVector.back ())->addWidget (ToolButtonVector.back ());
    algorithmTreeWidget->setItemWidget (SecondaryTreeWidgetItemVec.back (),0,WidgetVector.back ());


}









void Widget::GetSourceImage (){

cv::Mat cvImage= cv::imread ("h:/image/cell3.png",cv::IMREAD_GRAYSCALE);

if(cvImage.empty ()){
    QMessageBox::information (this,"","Open Image Fail!");
    return;
}

QImage qtImage(cvImage.data, cvImage.cols, cvImage.rows, cvImage.step, QImage::QImage::Format_Grayscale8);//将OpenCV图像转换为Qt的QImage
scene->addPixmap (QPixmap::fromImage (qtImage));
ui->graphicsView->setScene (scene);


/*
// 下面是一些傅里叶的扩展功能 暂时用不到
cv::Mat Image=cvImage;

int optimalSize=cv::getOptimalDFTSize (Image.rows);                                   // 获得最佳的dft尺寸
cv::Mat CV_64F_Image;                                                                // 复制一份要变换的图像
cv::Size size(optimalSize,optimalSize);
cv::resize (Image,Image,size);
cv::Mat complexImage;                                                             // 快速傅里叶变换后变换的图像 含有复数 ，因此它是无法直接显示的， 需要进行逆变换后才可以
Image.convertTo (CV_64F_Image,CV_64F,1.0/255.0);                                 // 在快速傅里叶变换前先转为CV_64F
cv::dft (CV_64F_Image,complexImage,cv::DFT_COMPLEX_OUTPUT);                     // 执行快速傅里叶变换 结果存放在complexImage中


// 显示变换后的幅度谱 && 移位幅度谱
cv::Mat magnitude;
cv::Mat planes[2];
cv::split(complexImage, planes);
cv::magnitude (planes[0],planes[1],magnitude);
magnitude += cv::Scalar::all(1);                                          // 防止在log运算中出现log(0)
cv::log(magnitude, magnitude);

int centerX1 = magnitude.cols / 2;
int centerY1 = magnitude.rows / 2;

cv::Mat q1(magnitude, cv::Rect(0, 0, centerX1, centerY1));
cv::Mat q2(magnitude, cv::Rect(centerX1, 0, centerX1, centerY1));
cv::Mat q3(magnitude, cv::Rect(0, centerY1, centerX1, centerY1));
cv::Mat q4(magnitude, cv::Rect(centerX1, centerY1, centerX1, centerY1));

cv::Mat tmp;
q1.copyTo(tmp);
q4.copyTo(q1);
tmp.copyTo(q4);
q2.copyTo(tmp);
q3.copyTo(q2);
tmp.copyTo(q3);

cv::normalize(magnitude, magnitude, 0, 1, cv::NORM_MINMAX);
cv::imshow("Magnitude Spectrum", magnitude);


cv::Mat Inverse_DFT_Image;

// 将变换后的矩阵取实部逆变换为为原来的图像 丢失了虚部的相位谱信息，逆变换后的效果并不好
//cv::idft (plans[0],Inverse_DFT_Image,cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);

// 包含实部和虚部 也就是包含幅度谱和相位谱 逆变换后的效果好
cv::idft (complexImage,Inverse_DFT_Image,cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
cv::normalize (Inverse_DFT_Image,Inverse_DFT_Image,0,1,cv::NORM_MINMAX);

cv::imshow ("Original Image",Image);
cv::imshow ("Inverse DFT Image",Inverse_DFT_Image);
cv::waitKey(0);
return;



int centerX=complexImage.cols/2;                                                          // 找到图像中心x坐标
int centerY=complexImage.rows/2;                                                         //  找到图像中心y坐标
int radius=300;
cv::Mat filter=cv::Mat::ones (complexImage.size(),complexImage.type ());               // 创建一个和complexImage图像一样大小 一样类型的矩阵 改造它为滤波矩阵
cv::Mat DestinationArray=cv::Mat::zeros (complexImage.size(),complexImage.type ());
cv::circle (filter,cv::Point(centerX,centerY),radius,cv::Scalar(0),0);               // 创建一个高通滤波器 在一个矩阵里画一个圆  圆圈内的元素为0 其余为-1
cv::multiply (complexImage,filter,DestinationArray);                                // 进行滤波操作 滤波后的图像依然存在complexImage中
cv::Mat invertedImage;                                                             // 矩阵
cv::idft (DestinationArray,invertedImage,cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);    // 进行逆变换操作
cv::normalize (invertedImage,invertedImage,0,255,cv::NORM_MINMAX);               // 对逆变换后的图像进行归一化操作
invertedImage.convertTo (invertedImage,CV_8U);                                  // 重置为CV_8U

cv::imshow ("原来的图像",Image);
cv::imshow ("filtter",invertedImage);
cv::waitKey (0);

return;*/
}




void Widget::FoulerFilttering(){
    cv::Mat cvImage= cv::imread ("h:/image/cell3.png",cv::IMREAD_GRAYSCALE);

    if(cvImage.empty ()){
        return;
    }

    cv::Mat Image=cvImage;

    int optimalSize=cv::getOptimalDFTSize (Image.rows);                   // 获得最佳的dft尺寸
    cv::Mat CV_64F_Image;                                                // 复制一份要变换的图像
    cv::Size size(optimalSize,optimalSize);
    cv::resize (Image,Image,size);
    cv::Mat complexImage;                                             // 快速傅里叶变换后变换的图像 含有复数 ，因此它是无法直接显示的， 需要进行逆变换后才可以
    Image.convertTo (CV_64F_Image,CV_64F,1.0/255.0);                 // 在快速傅里叶变换前先转为CV_64F
    cv::dft (CV_64F_Image,complexImage,cv::DFT_COMPLEX_OUTPUT);     // 执行快速傅里叶变换 结果存放在complexImage中
    cv:: Mat _Complex_Image_1=complexImage;
    // 创建高通滤波器（示例中使用1减去低通滤波器）
    cv::Mat highPassFilter = cv::Mat::ones(complexImage.size(), complexImage.type()) - cv::Mat::eye(complexImage.size(), complexImage.type());
    // 应用高通滤波器（在频域中相乘）
    cv::mulSpectrums(complexImage, highPassFilter, _Complex_Image_1, 0);
    // 执行逆傅里叶变换
    cv::Mat filteredImage;
    cv::idft(_Complex_Image_1, filteredImage, cv::DFT_REAL_OUTPUT);
    // 将第一个滤波器的结果写入磁盘
    cv::imwrite ("h:/image/ff3.png",filteredImage);



    // 下面是其他的高通滤波器 根据系数scale使用
    cv::Mat highPassFilter3 = cv::Mat::ones(complexImage.size(), complexImage.type()) - cv::Mat::eye(complexImage.size(), complexImage.type());
    // 缩放高通滤波器的系数以调整滤波效果，例如，增加系数以增加滤波效果 这里写死了  更方便点可以在控件中自定义
    double scale3 = 0.01;
    highPassFilter3 = highPassFilter3 * scale3;
    cv::mulSpectrums(complexImage, highPassFilter3, _Complex_Image_1, 0);
    cv::Mat filteredImage3;
    cv::idft(_Complex_Image_1, filteredImage3, cv::DFT_REAL_OUTPUT);
    cv::imwrite ("h:/image/ff1.png",filteredImage3);




    // 下面是其他的高通滤波器 根据系数scale使用
    cv::Mat highPassFilter2 = cv::Mat::ones(complexImage.size(), complexImage.type()) - cv::Mat::eye(complexImage.size(), complexImage.type());
    // 缩放高通滤波器的系数以调整滤波效果，例如，增加系数以增加滤波效果 这里写死了  更方便点可以在控件中自定义
    double scale = 0.02;
    highPassFilter2 = highPassFilter2 * scale;
    cv::mulSpectrums(complexImage, highPassFilter2, _Complex_Image_1, 0);
    cv::Mat filteredImage2;
    cv::idft(_Complex_Image_1, filteredImage2, cv::DFT_REAL_OUTPUT);
    cv::imwrite ("h:/image/ff2.png",filteredImage2);

    return;
}



void Widget::disPlayFiltterImage(){
    QPixmap pixmap1("h:/image/ff1.png");
    QPixmap pixmap2("h:/image/ff2.png");
    QPixmap pixmap3("h:/image/ff3.png");

    FiltterImageVec.push_back (pixmap1);
    FiltterImageVec.push_back (pixmap2);
    FiltterImageVec.push_back (pixmap3);

    scene2->addPixmap (pixmap2);
    ui->graphicsView_2->setScene (scene2);
}




void Widget::on_verticalSlider_sliderMoved(int position)
{

    Q_UNUSED (position);

    return;
}




void Widget::on_verticalSlider_valueChanged(int value)
{
    qDebug()<<value<<" ";
    switch (value) {
    case 1:
        scene2->addPixmap (FiltterImageVec.at (1));
        ui->graphicsView_2->setScene (scene2);
        break;
    case 2:
        scene2->addPixmap (FiltterImageVec.at (0));
        ui->graphicsView_2->setScene (scene2);
        break;
    case 3:
        scene2->addPixmap (FiltterImageVec.at (2));
        ui->graphicsView_2->setScene (scene2);
        break;
    }

}



/**
* 将所有new的资源释放
*/
void Widget::Free(){
    delete  checkBox1;
    delete  lineEdit1;
    delete  lineEdit2;
    delete  lineEdit3;
    delete  processBar;
    delete  processBar2;
    delete  treeVBoxLayout;
    delete  treeVBoxLayout2;

    // 最先释放小组件
    for(auto iterator=LabelVector.begin ();iterator!=LabelVector.end ();iterator++){
        if(*iterator!=nullptr){
            delete (*iterator);
        }
    }


    for(auto iterator=ComboxVector.begin ();iterator!=ComboxVector.end ();iterator++){
        if(*iterator!=nullptr){
            delete (*iterator);
        }
    }


    for(auto iterator=ToolButtonVector.begin ();iterator!=ToolButtonVector.end ();iterator++){
        if(*iterator!=nullptr){
            delete (*iterator);
        }
    }


    for(auto iterator=DoubleSpinBoxVec.begin ();iterator!=DoubleSpinBoxVec.end ();iterator++){
        if(*iterator!=nullptr){
            delete (*iterator);
        }
    }


    for(auto iterator=AlgoTreeWdCheckBoxVec.begin ();iterator!=AlgoTreeWdCheckBoxVec.end ();iterator++){
        if(*iterator!=nullptr){
            delete (*iterator);
        }
    }


    for(auto iterator=SpinBoxVector.begin ();iterator!=SpinBoxVector.end ();iterator++){
        if(*iterator!=nullptr){
            delete (*iterator);
        }
    }


    // 释放布局 此时布局里已经没有了小组件的资源
    for(auto iterator=WidgetHBoxLayoutVector.begin ();iterator!=WidgetHBoxLayoutVector.end ();iterator++){
        if(*iterator!=nullptr){
            delete (*iterator);
        }
    }


    // 释放由布局和小组件做成的widget 此时widget里已经没有了布局资源 没有了小组件资源 这里的这些widget都在二级标题下管理
    for(auto iterator=WidgetVector.begin ();iterator!=WidgetVector.end ();iterator++){
        if(*iterator!=nullptr){
            delete (*iterator);
        }
    }

    // 释放二级标题 此时二级标题下已经没有了任何 widget资源
    for(auto iterator=SecondaryTreeWidgetItemVec.begin ();iterator!=SecondaryTreeWidgetItemVec.end ();iterator++){
        if(*iterator!=nullptr){
            delete (*iterator);
        }
    }

    // 释放一级标题资源
    for(auto iterator=TreeWidgetItemVector.begin ();iterator!=TreeWidgetItemVector.end ();iterator++){
        if(*iterator!=nullptr){
            delete (*iterator);
        }
    }


    // 释放掉显示的view组件
    delete scene;
    // 释放两个创建的树形窗口
    delete  hardwareTreeWidget;
    delete  algorithmTreeWidget;

}





